package com.cwvs.cat.adapter;

import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.cwvs.cat.Applications;
import com.cwvs.cat.FoundActiveDetailActivity;
import com.cwvs.cat.R;
import com.cwvs.cat.WebActivity;
import com.cwvs.cat.util.EncryptUtil;

public class FoundStoreListAdapter extends BaseAdapter {

	private Activity mContent;
	private List<String> list_contact;
	private LayoutInflater inflater;

	public FoundStoreListAdapter() {
		// TODO Auto-generated constructor stub
	}

	public FoundStoreListAdapter(Activity ac, List<String> list) {
		// TODO Auto-generated constructor stub
		this.mContent = ac;
		this.inflater = LayoutInflater.from(ac);
		this.list_contact = list;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list_contact.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list_contact.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder viewholder;
		if(convertView==null){
			convertView = inflater.inflate(R.layout.item_list_found_store, null);
			viewholder = new ViewHolder();
			viewholder.txt_found_store_name=(TextView) convertView.findViewById(R.id.txt_found_store_name);
			convertView.setTag(viewholder);

		}else{
			viewholder = (ViewHolder) convertView.getTag();
		}

		convertView.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent=new Intent();
				String userid = EncryptUtil.encryptBASE64(Applications.user.id);
				System.out.println(userid);
				String dest[] = {"\\/","\\+","="};
				String replace[] = {":","\\|",";"};
				for (int i = 0; i < dest.length; i++) {
					userid = userid.replaceAll(dest[i], replace[i]);
				}
				System.out.println(userid);
//				intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://pet.xlingmao.com/index.php?&g=Wap&m=Storex&a=index&token=pwhyqt1426234042&maomeng=" + userid));
				String url = "http://pet.xlingmao.com/index.php?&g=Wap&m=Storex&a=index&token=" + "pwhyqt1426234042" + "&maomeng=" + userid;
				intent = new Intent(mContent, WebActivity.class);
				intent.putExtra("url", url);
				mContent.startActivity(intent);
				
				
			}
		});
		viewholder.txt_found_store_name.setText(list_contact.get(position));
		return convertView;
	}

	class ViewHolder {
		TextView txt_found_store_name, txt_found_store_time,
		txt_found_store_address;

	}

}
